package com.util;

import com.alibaba.fastjson.JSONObject;
import com.domain.InitDomain;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;

public class FileUtil {

    public static HashMap<String,Object> init(String initFileName){
        HashMap<String, Object> resultHashMap = new HashMap<>();
        File file = new File(initFileName);
        //读取文件
        try {
            FileInputStream fileInputStream = new FileInputStream(file);
            StringBuilder sb = new StringBuilder();
            int flag;
            while((flag=fileInputStream.read())!=-1){
                sb.append((char)flag);
            }
            InitDomain initDomain = JSONObject.parseObject(sb.toString(), InitDomain.class);
            resultHashMap.put("success", initDomain);
        } catch (FileNotFoundException e) {
            resultHashMap.put("fileNotFound", "FileNotFound");
        } catch (IOException e) {
            resultHashMap.put("iOException", "IOException");
        }
        return resultHashMap;
    }

}
